import os
from typing import Pattern
from unittest import result
import readConfig
import unittest
from BeautifulReport import BeautifulReport as Bf
localPath=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
result_Path=localPath + "\\result"
FileList=localPath+"\\testfile"
print(localPath)
print(FileList)
class Execute_All:
    def __init__(self):
        self.caselist=[]
    def set_case_list(self):
        for file in FileList:
            f=open(file,'w')
            for data in f.readlines():
                data =str(data)
                if data!='' and data.startswith("#"):
                    self.caselist.append(data.replace("\n",""))
            f.close()
    def set_case_suite(self):
        self.set_case_list()
        test_suite=unittest.TestSuite()
        suite_model =[]
        for case in self.caselist:
            case_file=os.path.join(readConfig.pro_dir,"testcase")
            case_name =case.split("/")[-1]
            discover=unittest.defaultTestLoader(case_file,pattern=case_name + '.py',top_level_dir=None)
        if len(suite_model)>0:
            for suite in suite_model:
                for test_name in suite:
                    test_suite.addTest(test_name)
        else:
            return None
        return test_suite
    def run(self):
        suite =self.set_case_suite()
        result=Bf(suite)
        report =result.report(description="测试报告",filename="自动化报告",log_path=result_Path)

        

    